import React from 'react'
import Loading from 'component/Loading/Loading.jsx'
/**
 * <ScrollView loadCallback={func} isend={bool}/>滚动加载组件
 *  */ 
class ScrollView extends React.Component {

    componentDidMount(){
        window.addEventListener("scroll", this.onLoadPage)
    }
    componentWillUnmount(){
        window.removeEventListener("scroll", this.onLoadPage)
    }
    // 滚动方法
    onLoadPage =() => {
        let clientHeight = document.documentElement.clientHeight
        let scrollHeight = document.body.scrollHeight;
        let scroll = document.documentElement.scrollTop;

        let proLoadDis = 30;

        if ((scroll + clientHeight) >= (scrollHeight - proLoadDis)){
            if(!this.props.isend){
                this.props.loadCallback && this.props.loadCallback()
            }        
            
        }
    }

    render(){
        return <div className="scrollview">
            {this.props.children}
            <Loading isend={this.props.isend}></Loading>
        </div>
    }
}

export default ScrollView